﻿package mortal.game.view.mainUI.actionIcon
{
    import com.gengine.core.frame.*;
    import com.mui.controls.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;

    public class ActionIconOneLineSp extends GSprite
    {
        public var colCount:int = 10;
        private const iconWidth:int = 65;
        private const iconHeight:int = 65;
        public var iconArr:Array;
        private var _shrikeBtn:GLoadingButton;
        private var _shrikeBtnOpen:GLoadingButton;
        public var container:GSprite;
        private var _len:int;
        private var _isMoving:Boolean = false;
        private var _isHide:Boolean = false;
        public var parentSp:DisplayObjectContainer;
        private var _timer:FrameTimer;
        private var _dir:int = -1;
        private var _step:int = 90;
        private var _endPos:int = 0;
        private var _begX:int = 0;

        public function ActionIconOneLineSp()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._shrikeBtn = UIFactory.gLoadingButton(ImagesConst.ActionIconShrikeBtn_upSkin, -1, 6, 29, 44, this);
            this._shrikeBtnOpen = UIFactory.gLoadingButton(ImagesConst.ActionIconShrikeLeftBtn_upSkin, -1, 6, 29, 44, this);
            this._shrikeBtnOpen.visible = false;
            this.container = UIFactory.getUICompoment(GSprite);
            this.addChild(this.container);
            this._shrikeBtn.configEventListener(MouseEvent.CLICK, this.onShrikeHd);
            this._shrikeBtnOpen.configEventListener(MouseEvent.CLICK, this.onShrikeHd);
            this.iconArr = [];
            this._timer = new FrameTimer(1);
            this._timer.isRepair = false;
            this._timer.addListener(TimerType.ENTERFRAME, this.onEnterFrameHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            var _loc_2:int = 0;
            var _loc_3:ActionBaseIcon = null;
            super.disposeImpl(param1);
            if (this.iconArr)
            {
                _loc_2 = 0;
                while (_loc_2 < this.iconArr.length)
                {
                    
                    _loc_3 = this.iconArr[_loc_2];
                    if (_loc_3)
                    {
                        _loc_3.removeEventListener(EventName.ActionIconPlayEffect, this.onEffectHd);
                    }
                    _loc_2++;
                }
            }
            EffectManager.glowFilterUnReg(this._shrikeBtnOpen);
            this.container.mask = null;
            this._timer.dispose(param1);
            while (this.container.numChildren > 0)
            {
                
                this.container.removeChildAt(0);
            }
            this.iconArr.length = 0;
            this._shrikeBtn.dispose(param1);
            this._shrikeBtnOpen.dispose(param1);
            this.container.dispose(param1);
            this._shrikeBtn = null;
            this._shrikeBtnOpen = null;
            this.container = null;
            this.iconArr = null;
            this._isHide = false;
            this.parentSp = null;
            this._begX = 0;
            return;
        }// end function

        private function onEffectHd(param1:Object) : void
        {
            var _loc_2:int = 0;
            var _loc_3:ActionBaseIcon = null;
            EffectManager.glowFilterUnReg(this._shrikeBtnOpen);
            if (this._isHide)
            {
                _loc_2 = 0;
                while (_loc_2 < this.iconArr.length)
                {
                    
                    _loc_3 = this.iconArr[_loc_2];
                    if (_loc_3 && _loc_3.isPlayEffect)
                    {
                        EffectManager.glowFilterReg(this._shrikeBtnOpen, [FilterConst.chatTipsFilter], 0.6, 20, 2, 0);
                        break;
                    }
                    _loc_2++;
                }
            }
            return;
        }// end function

        private function onShrikeHd(event:MouseEvent) : void
        {
            if (this._isMoving)
            {
                return;
            }
            GameController.autoGuide.checkAndStopGuiding();
            this._isMoving = true;
            if (this._isHide)
            {
                this._isHide = false;
                this.rightBtn(true);
                this._dir = -1;
                this._endPos = 0;
                this._timer.start();
            }
            else
            {
                this._isHide = true;
                this.rightBtn(false);
                this._dir = 1;
                this._endPos = this.iconArr.length * this.iconWidth + 40;
                this._timer.start();
            }
            return;
        }// end function

        private function onEnterFrameHandler(param1) : void
        {
            this._begX = this._begX + this._dir * this._step;
            if (this._dir == -1 && this._begX <= this._endPos)
            {
                this._timer.stop();
                this.onCompleteHd();
                this._begX = this._endPos;
            }
            if (this._dir == 1 && this._begX >= this._endPos)
            {
                this._timer.stop();
                this.onCompleteHd();
                this._begX = this._endPos;
            }
            this.moveLayOutIcons();
            return;
        }// end function

        private function rightBtn(param1:Boolean) : void
        {
            if (param1)
            {
                this._shrikeBtnOpen.visible = false;
                this._shrikeBtn.visible = true;
                EffectManager.glowFilterUnReg(this._shrikeBtnOpen);
            }
            else
            {
                this._shrikeBtnOpen.visible = true;
                this.onEffectHd(null);
                this._shrikeBtn.visible = false;
            }
            return;
        }// end function

        private function onCompleteHd() : void
        {
            this._isMoving = false;
            return;
        }// end function

        private function setLen(param1:int = 10) : void
        {
            this._len = param1;
            return;
        }// end function

        public function addIcon(param1:DisplayObject) : void
        {
            GameController.autoGuide.checkAndStopGuiding();
            if (this.iconArr.indexOf(param1) == -1)
            {
                this.iconArr.push(param1);
            }
            if (param1.hasEventListener(EventName.ActionIconPlayEffect) == false)
            {
                param1.addEventListener(EventName.ActionIconPlayEffect, this.onEffectHd);
            }
            if (param1 && this.parentSp && this.parentSp.contains(param1) == false)
            {
                this.parentSp.addChild(param1);
            }
            if (this._isHide)
            {
                this._begX = (this.iconArr.length + 2) * this.iconWidth + 40;
                this.moveAll(this._begX);
                this.onEffectHd(null);
            }
            return;
        }// end function

        public function removeIcon(param1:DisplayObject) : void
        {
            GameController.autoGuide.checkAndStopGuiding();
            var _loc_2:* = this.iconArr.indexOf(param1);
            if (_loc_2 != -1)
            {
                this.iconArr.splice(_loc_2, 1);
                param1.removeEventListener(EventName.ActionIconPlayEffect, this.onEffectHd);
            }
            this.layOutIcons();
            return;
        }// end function

        private function moveAll(param1:int) : void
        {
            this._begX = param1;
            this.layOutIcons();
            return;
        }// end function

        public function layOutIcons() : void
        {
            var _loc_3:DisplayObject = null;
            var _loc_1:int = 0;
            if (this._isHide)
            {
                _loc_1 = this.iconArr.length * this.iconWidth + 40;
            }
            else
            {
                _loc_1 = 0;
            }
            var _loc_2:int = 0;
            while (_loc_2 < this.iconArr.length)
            {
                
                _loc_3 = this.iconArr[_loc_2];
                _loc_3.x = _loc_1 + (_loc_2 + 1) * (-this.iconWidth);
                _loc_2++;
            }
            return;
        }// end function

        public function moveLayOutIcons() : void
        {
            var _loc_2:DisplayObject = null;
            var _loc_1:int = 0;
            while (_loc_1 < this.iconArr.length)
            {
                
                _loc_2 = this.iconArr[_loc_1];
                _loc_2.x = this._begX + (_loc_1 + 1) * (-this.iconWidth);
                _loc_1++;
            }
            return;
        }// end function

        public function layY() : void
        {
            var _loc_2:DisplayObject = null;
            var _loc_1:int = 0;
            while (_loc_1 < this.iconArr.length)
            {
                
                _loc_2 = this.iconArr[_loc_1];
                _loc_2.y = this.y;
                _loc_1++;
            }
            return;
        }// end function

        public function get isHide() : Boolean
        {
            return this._isHide;
        }// end function

        public function set isHide(param1:Boolean) : void
        {
            GameController.autoGuide.checkAndStopGuiding();
            this._isHide = param1;
            this.rightBtn(!this._isHide);
            if (this._isHide)
            {
                this.moveAll(this.iconArr.length * this.iconWidth + 40);
            }
            else
            {
                this.moveAll(0);
            }
            return;
        }// end function

        public function adjustContainer() : void
        {
            if (this._isHide)
            {
                this.moveAll(this.iconArr.length * this.iconWidth + 40);
            }
            return;
        }// end function

    }
}
